package org.azj.ColumnInfoReader;
import java.io.File;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

import org.azj.inireader.FieldBasicInfo;


public class MainClass {

	public static void main(String[] args) {
		
		// one instance can read only one ini file, if you want to read from several files, 
		// you should make several separate instances
		ColumnInfoReader xmlReader = new ColumnInfoReader();
		File directory = new File("");
		
		try {
			xmlReader.read(directory.getAbsolutePath() + "\\testdata\\columninfo.xml");
		} catch (Exception e) {
			System.out.println(String.format("Error met : \n%s", e.getMessage()));
			return;
		}
		
		// test 1
		// 中文->信息
		System.out.println("test 1");
		FieldBasicInfo fbi = xmlReader.getValueByDescription("TBL1", "属性1");
		PrintInfo("属性1", fbi);
		
		// test 2
		System.out.println("test 2");
		HashMap<String, FieldBasicInfo> mapFbi = xmlReader.getValuesByDescription();
		Set<String> keys = xmlReader.getKeysInDescription();
		
		Iterator<String> it = keys.iterator();
		while (it.hasNext()) {
			String str = it.next();
			PrintInfo(str, mapFbi.get(str));
		}
		
		// test 3
		// 字段->信息
		System.out.println("test 3");
		fbi = xmlReader.getValueByField("TBL2", "attr3");
		PrintInfo("attr3", fbi);
				
		// test 4
		System.out.println("test 4");
		HashMap<String, FieldBasicInfo> mapFbiByFields = xmlReader.getValuesByFields();
		keys = xmlReader.getKeysInFields();
				
		it = keys.iterator();
		while (it.hasNext()) {
			String str = it.next();
			PrintInfo(str, mapFbiByFields.get(str));
		}
		
//		// test 5
//		System.out.println("test 5");
//		HashMap<String, FieldBasicInfo> tmp = iniReaderHelper.getValuesByFields("TBL2");
//		keys = iniReaderHelper.getKeysInFields("TBL2");
//				
//		it = keys.iterator();
//		while (it.hasNext()) {
//			String str = it.next();
//			PrintInfo(str, tmp.get(str));
//		}
//		
//		// test 6
//		System.out.println("test 6");
//		HashMap<String, FieldBasicInfo> tmp2 = iniReaderHelper.getValuesByDescription("TBL2");
//		keys = tmp2.keySet();
//				
//		it = keys.iterator();
//		while (it.hasNext()) {
//			String str = it.next();
//			PrintInfo(str, tmp2.get(str));
//		}
	}
	
	private static void PrintInfo(String key, FieldBasicInfo fbi)
	{
		String msg = String.format("key=%s, TableName=%s, FieldName=%s, Des=%s, CanOmit=%s", 
				key, fbi.TableName, fbi.FieldName, fbi.DescribeName.toString(), fbi.canOmit);
		System.out.println(msg);
	}
}
